<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    * {
        margin: 0;
        padding: 0;
    }
    .container {
        width: 400px;
        margin: 0 auto;
    }
    h2 {
        text-align: center;
        /* 拉开距离 */
        padding: 20px 0;
    }
    p {
        color: #666;
        font-size: 14px;
        text-align: center;
        padding: 10px 0;
    }
    .row {
        display: flex;
        /* 上下和左右居中后,设置高度来个各个div之间的距离 */
        justify-content: center;
        align-items: center;
        height: 40px;
    }
    /* 占位符 */
    span {
        width: 100px;
    }
    .message {
        height: 25px;
        width: 200px;
    }
    .submit {
        width: 300px;
        height: 30px;
        color: white;
        border: none;
        background-color: orange;
    }
    .submit:active {
        background-color: gray;
    }
</style>
<body>
    <div class="container">
        <h2>表白墙</h2>
        <p>输入后点击提交,会将信息保存在表格中</p>
        <div class="row">
            <span>谁</span>
            <input type="text" name="" id="" class="message">
        </div>
        <div class="row">
            <span>对谁</span>
            <input type="text" name="" id="" class="message">
        </div>
        <div class="row">
            <span>说什么</span>
            <input type="text" name="" id="" class="message">
        </div>
        <div class="row">
            <input type="submit" value="提交" class="submit">
        </div>
    </div>
</body>
<script>
    let submit = document.querySelector('.submit');
    let message = document.querySelectorAll('.message');
    //submit的onclick没有补全,但是是可以用的,是补全的问题
    submit.onclick = function()
    {
        //1.获取输入框的内容
        let who = message[0].value;
        let to = message[1].value;
        let mess = message[2].value;
        if(who == '' || to == '' || mess == '')
        {
            return;
        }
        //2.创建元素
        let div = document.createElement('div');
        // 居中
        div.className = 'row';
        div.innerHTML = who + '想对' + to + '说' + mess;
        //3.添加到dom树里面
        let container = document.querySelector('.container');
        container.appendChild(div);
        //4.清除表格的内容
        for(i = 0; i < 3; ++i)
        {
            message[i].value = '';
        }
    }
</script>
</html>

